/**
 * 响应拦截
 * @param {Object} http 
 */
import useStore from '@/store'
export const responseInterceptors = (vm) => {
    uni.$uv.http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/
        uni.hideLoading();
		const data = response.data
        if (data.code != 1) {
            uni.$uv.toast(data.msg);
        }
        return data || {}
    }, (response) => { /*  对响应错误做点什么 （statusCode !== 200）*/
		const store = useStore();
		uni.hideLoading();
		// 未登录跳转到登录页面
		if(response.data.code == 401){
			store.token = '';
			store.userinfo = {};
			uni.showToast({
				title: response.data.msg,
				icon: 'none',
				duration: 1500,
                mask: true
			});
            const time = setTimeout(() => {
                uni.navigateTo({
                    url: '/pages/login/login'
                })
                clearTimeout(time);
            }, 1500)
		}
        return Promise.reject(response)
    })
}